package org.nViron.nvOrganic;

//~--- non-JDK imports --------------------------------------------------------

import org.nViron.nvData.nvDataEntity;
import org.nViron.nvParams.nvContextParamMgr.CONTEXTPARAM;
import org.nViron.nvParams.nvVizParamMgr.VIZPARAM;
import org.nViron.nvRender.nvRenderer;

/**
 * A Stalk is the joint between a node and a leaf
 * @author Roland Haring <p>
 * <script type="text/javascript" src="http://www.ohloh.net/p/376434/widgets/project_basic_stats.js"></script>
 */
public class nvStalk extends nvJoint {
    private final nvLeaf leaf;

    public nvStalk(nvOrganic organic, nvKinetic parent, nvDataEntity entity) {
        super(organic, parent);
        leaf = new nvLeaf(organic, this, entity);
        setDestination(leaf);
    }

    @Override
    public void addEntity(nvDataEntity entity) {
        leaf.addEntity(entity);
    }

    @Override
    public void degenerate() {
        leaf.degenerate();
    }

    public nvDataEntity getEntity() {
        return leaf.getEntity();
    }

    public nvLeaf getLeaf() {
        return leaf;
    }

    @Override
    public int getNumEntities() {
        return leaf.getNumEntities();
    }

    public float getSimilarityTo(nvDataEntity entity) {
        return leaf.getSimilarityTo(entity);
    }

    public float getSimilarityTo(nvDataEntity other, CONTEXTPARAM contextParam) {
        return leaf.getSimilarityTo(other, contextParam);
    }

    public float getSimilarityTo(nvDataEntity other, VIZPARAM vizParam) {
        return leaf.getSimilarityTo(other, vizParam);
    }

    @Override
    public float getVizValue(VIZPARAM param) {
        return leaf.getVizValue(param);
    }

    @Override
    public void remove() {
        leaf.remove();
        super.remove();
    }

    @Override
    public boolean removeEntity(nvDataEntity entity) {
        return leaf.removeEntity(entity);
    }

      public void render(nvRenderer renderer) {
        if (!isRenderable()) {
            return;
        }

        renderer.renderStalk(this);
        leaf.render(renderer);
    }

    @Override
    protected void setSelection(boolean b) {
        super.setSelection(b);

        // recursivly
        if (leaf != null) {
            leaf.setSelection(b);
        }
    }

    @Override
    public void update(float timeStep) {
        super.update(timeStep);
        leaf.update(timeStep);
        updateStateRelativeToChild(leaf);
    }

    @Override
    public void updateVizValue(VIZPARAM param) {
        leaf.updateVizValue(param);
    }
}



